home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------------------------------
- *
- * IPM MessageBoard AOCE Sample
- *
- * ©1992-1993 Apple Computer
- *
- -------------------------------------------------------------------------------------*/
- /*
- * commands.c -- called in response to menu commands or appleevents
- *
- * change history:
- *
- * SJF 2/12/93 1.0b1 udpate to AOCE beta seed
- * SJF 11/6/91 1.0d1 initial coding
- *
- */
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
-
- #ifndef __LISTS__
- #include <Lists.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #include "const.h"
- #include "mymenus.h"
- #include "globals.h"
- #include "utils.h"
- #include "commands.h"
- #include "myipm.h"
-
- #include "statusdialog.h"
-
-
- /* macros */
-
- #define GetDlogData(dlog) ((DlogDataPtr)GetWRefCon((WindowPtr)dlog))
-
-
- /* init our dialog */
-
- void MakeMainDialog(void)
- {
- Rect iRect;
- Handle iHndl;
- short iType;
- DlogDataPtr dlogData;
- Rect dataBounds;
- Point cellSize = {0,0};
-
- dlogData = (DlogDataPtr) NewPtr(sizeof(DlogData));
- if (MemError()!=noErr) {
- DoError(MemError());
- ExitToShell();
- }
-
- gMainDialog = GetNewDialog(kStatusBoxID,nil,kInFront);
- SetPort(gMainDialog);
- SetRect(&dataBounds,0,0,1,0);
-
- GetDItem(gMainDialog,kMsgListDItem,&iType,&iHndl,&iRect);
- SetDItem(gMainDialog,kMsgListDItem,iType,(Handle)DrawScrollList,&iRect);
- dlogData->msgList = LNew(&iRect,&dataBounds,cellSize,0,gMainDialog,true,false,false,true);
- (**(dlogData->msgList)).selFlags |= lOnlyOne;
-
- GetDItem(gMainDialog,kDestListDItem,&iType,&iHndl,&iRect);
- SetDItem(gMainDialog,kDestListDItem,iType,(Handle)DrawScrollList,&iRect);
- dlogData->destList = LNew(&iRect,&dataBounds,cellSize,0,gMainDialog,true,false,false,true);
- (**(dlogData->destList)).selFlags |= lOnlyOne;
-
- GetDItem(gMainDialog,kMsgScrollDItem,&iType,&iHndl,&iRect);
- SetDItem(gMainDialog,kMsgScrollDItem,iType,(Handle)DrawEmptyItem,&iRect);
-
- GetDItem(gMainDialog,kDestScrollDItem,&iType,&iHndl,&iRect);
- SetDItem(gMainDialog,kDestScrollDItem,iType,(Handle)DrawEmptyItem,&iRect);
-
- GetDItem(gMainDialog,kSeparatorDItem,&iType,&iHndl,&iRect);
- SetDItem(gMainDialog,kSeparatorDItem,iType,(Handle)DrawGraySeparator,&iRect);
-
- // turn new selection on
- GetDItem(gMainDialog,kAtalkAddrBtn,&iType,&iHndl,&iRect);
- SetCtlValue((ControlHandle)iHndl,kCtlOn);
-
- // save current selection
- gRadioBtnSelected = kAtalkAddrBtn;
-
- SetWRefCon(gMainDialog,(long)dlogData);
- }
-
-
- void CloseMainDialog(void)
- {
- DisposeDialog(gMainDialog);
- }
-
-
- pascal void DrawScrollList(DialogPtr theDlg,short item)
- {
- ListHandle theList;
- Rect iRect;
-
- theList = GetListFromItem(theDlg,item);
- PenNormal();
-
- iRect = (**theList).rView;
- InsetRect(&iRect,-1,-1);
- FrameRect(&iRect);
- LUpdate(theDlg->visRgn,theList);
- }
-
-
- pascal void DrawGraySeparator(DialogPtr theDlg,short item)
- {
- Rect iRect;
- Handle iHndl;
- short iType;
- PenState thePenState;
-
- GetPenState(&thePenState);
- PenNormal();
-
- GetDItem(theDlg,item,&iType,&iHndl,&iRect);
- FillRect(&iRect,qd.gray);
-
- SetPenState(&thePenState);
- }
-
-
- pascal void DrawEmptyItem(DialogPtr theDlg,short item)
- {
- #pragma unused (theDlg,item)
- }
-
-
- ListHandle GetListFromItem(DialogPtr theDlg,short item)
- {
- DlogDataPtr dlogData;
-
- dlogData = GetDlogData(theDlg);
-
- switch (item) {
- case kMsgListDItem:
- return dlogData->msgList;
- break;
- case kDestListDItem:
- return dlogData->destList;
- break;
- default:
- DoError(kInternalError);
- return nil;
- break;
- }
- }
-
-
- short GetSelectedMessage(void)
- {
- DlogDataPtr dlogData;
- ListHandle theList;
- Cell theCell = {0,0};
-
- dlogData = GetDlogData(gMainDialog);
- theList = dlogData->msgList;
-
- if (LGetSelect(true,&theCell,theList))
- return theCell.v;
- else
- return -1;
- }
-
-
- short GetSelectedDestination(void)
- {
- DlogDataPtr dlogData;
- ListHandle theList;
- Cell theCell = {0,0};
-
- dlogData = GetDlogData(gMainDialog);
- theList = dlogData->destList;
-
- if (LGetSelect(true,&theCell,theList))
- return theCell.v;
- else
- return -1;
- }
-
-
- void AddItemToList(short msgNum,short whichList)
- {
- ListHandle theList;
-
- Cell testCell = {0,0};
-
- theList = GetListFromItem(gMainDialog,whichList);
- LAddRow(1,msgNum,theList);
- EditItemInList(msgNum,whichList);
- }
-
-
- void EditItemInList(short msgNum,short whichList)
- {
- Cell theCell;
- ListHandle theList;
- Str255 destString;
-
- theCell.h = 0;
- theCell.v = msgNum;
- theList = GetListFromItem(gMainDialog,whichList);
-
- if (whichList==kMsgListDItem)
- LSetCell(&gMessageList[msgNum][1],gMessageList[msgNum][0],theCell,theList);
- else {
- GetDestAsString(msgNum,destString);
- LSetCell(&destString[1],destString[0],theCell,theList);
- }
- }
-
- void HandleButtons(DialogPtr theDlg, short buttonSelected)
- {
- Rect iRect;
- Handle iHndl;
- short iType;
-
- // turn current selection off
- GetDItem(theDlg,gRadioBtnSelected,&iType,&iHndl,&iRect);
- SetCtlValue((ControlHandle)iHndl,kCtlOff);
-
- // turn new selection on
- GetDItem(theDlg,buttonSelected,&iType,&iHndl,&iRect);
- SetCtlValue((ControlHandle)iHndl,kCtlOn);
-
- // save current selection
- gRadioBtnSelected = buttonSelected;
- }
-
-
- /* handles events important to our dialog
- */
-
- Boolean HandleDialogEvents(EventRecord *ev)
- {
- DialogPtr theDlg;
- short item;
-
- if (!IsDialogEvent(ev))
- return false;
-
- if (DialogSelect(ev,&theDlg,&item)) {
- switch (item) {
- case kSendDItem:
- CommSendMessage(GetSelectedMessage(),GetSelectedDestination());
- break;
- case kViewDItem:
- CommViewMessage(GetSelectedMessage());
- break;
- case kMakeMsgDItem:
- CommMakeMessage();
- break;
- case kMakeDestDItem:
- CommMakeDestination();
- break;
- case kMsgScrollDItem:
- case kDestScrollDItem:
- item -= 2; // fall thru to list items
- case kMsgListDItem:
- case kDestListDItem:
- SetPort(theDlg);
- GlobalToLocal(&ev->where);
- LClick(ev->where,ev->modifiers,GetListFromItem(theDlg,item));
- break;
- case kAtalkAddrBtn:
- case kCreateServerQBtn:
- case kOpenServerQBtn:
- case kPrefMsgQBtn:
- case kMailSlotBtn:
- HandleButtons(theDlg,item);
- break;
-
- }
- return true;
- }
-
- return false;
- }
-
-
-